const BaseController = require("./base");

class CommonsController extends BaseController {
    async citys() {
        const { ctx, app } = this;

        try {
            const result = await app.httpclient.request("https://api.xiaohuwei.cn/test.php?type=province", {
                dataType: "json",
            });
            const city = result.data.provincelist.map((province) => {
                return { label: province.city, value: province.pid };
            });
            if (result.status === 200) {
                this.success(city);
            } else {
                this.error("获取城市数据失败");
            }
        } catch (error) {
            this.error("获取城市数据失败");
        }
    }
}

module.exports = CommonsController;
